package com.itheima.question.controller;

import com.itheima.PageVo;
import com.itheima.Result;
import com.itheima.admin.dto.PageDto;
import com.itheima.admin.dto.QuestionDto;
import com.itheima.admin.vo.QuestionVo;
import com.itheima.admin.vo.RoleVo;
import com.itheima.question.service.IQuestionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;

    @GetMapping("/{id}")
    @ApiOperation("通过id查询题目")
    public QuestionDto queryQuestionById(@PathVariable("id") String id){
        return questionService.queryQuestionById(id);
    }

    @PostMapping("/add")
    @ApiOperation("添加题目")
    public Result addQuestion(@RequestBody QuestionDto questionDto){
        boolean b = questionService.addQuestion(questionDto);
        return new Result(b,b?"添加成功":"添加失败",null);
    }

    @PostMapping("/list")
    @ApiOperation("分页查询题目列表")
    public PageVo<QuestionVo> queryByPage(@RequestBody PageDto pageDto){
        return questionService.queryByPage(pageDto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除题目")
    public Result deleteById(@PathVariable("id") String id){
        boolean result = questionService.deleteById(id);
        return new Result(result,result?"删除用户成功":"删除用户失败",null);
    }

}
